<template>
  <div class="shops">
    <div class="warp">
      <div class="shopss">
        <div class="shopimg" v-show="shows">
          <img src="../../assets/img/星空.jpg" alt="" />
        </div>
        <table v-show="yc">
          <tr v-for="item in $store.state.shop" :key="item.id">
            <td>
              <input type="checkbox" @click="checkeds" v-model="checkbox" />
              <img :src="item.pic" alt="" />
              <p>
                <span>
                  {{ item.name }}
                </span>
                <span>
                  {{ item.weight }}
                </span>
                <span class="red">
                  {{ "￥" + item.minPrice }}
                </span>
              </p>
              <span class="setter"> </span>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <ul id="shopings"></ul>
    <div class="lickss">
      <div class="lick">
        <p class="lick-p">猜你喜欢</p>
        <ul>
          <li v-for="(item, i) in list" :key="i">
            <p class="p-img">
              <img :src="item.pic" alt="" />
            </p>
            <p v-html="item.name" class="p1"></p>
            <p v-html="item.name" class="p2"></p>
            <p v-html="'￥' + item.minPrice" class="p3"></p>
          </li>
        </ul>
      </div>
    </div>
    <div class="gotoprice" v-show="yc">
      <p>
        <input type="checkbox" @click="allchecked" v-model="checked" />
        全选
      </p>
      <p class="allprice">
        合计: <span class="allprices">{{ price }}</span>
      </p>
      <p class="xd">
        下单
      </p>
    </div>
  </div>
</template>
<script>
import { getHits } from "../../utils/api";
export default {
  data() {
    return {
      checked: false,
      checkbox: false,
      result: [],
      shows: true,
      yc: false,
      list: [],
    };
  },

  mounted() {
    var aa = rand(6, 1);
    getHits(aa).then((res) => {
      this.list = res.data;
      console.log(this.list);
    });
    if (this.$store.state.shop.length == 0) {
      this.shows = true;
      this.yc = false;
    } else {
      this.shows = false;
      this.yc = true;
    }
    function rand(max, min) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }
  },
  methods: {
    //全选
    allchecked() {
      if (this.checked == true) {
        this.checkbox = true;
      } else if (this.checked == false) {
        this.checkbox = false;
      }
    },
    //单选
    checkeds() {},
  },
  computed: {
    price() {
      let ff = 0;
      this.$store.state.shop.forEach((item) => {
        ff += parseInt(item.num * item.minPrice);
      });
      return ff;
    },
  },
};
</script>

<style lang="scss" scoped>
.warp {
  width: 100%;
  height: 50%;
  overflow: auto;
}
.shops {
  width: 100%;
  height: 100%;
  .shopss {
    width: 100%;
    height: 50%;
    margin-top: 1rem;
    .shopimg {
      width: 100%;
      height: 100%;
      background: red;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  table {
    width: 100%;
    td {
      display: flex;
      align-items: center;
      padding-left: 0.3rem;
      height: 2rem;
      position: relative;
      p {
        padding-left: 0.3rem;
        line-height: 0.6rem;
        span {
          display: block;
        }
        .red {
          color: red;
        }
      }
    }
    .setter {
      width: 2rem;
      height: 0.5rem;
      position: absolute;
      right: 0.02rem;
      top: 1.3rem;
    }
    img {
      display: block;
      padding-left: 0.3rem;
      width: 1.5rem;
      height: 1.7rem;
    }
  }
  .gotoprice {
    width: 100%;
    height: 7vh;
    background: white;
    position: fixed;
    bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    p {
      padding-left: 0.3rem;
    }
    .allprice {
      width: 2.5rem;
      text-align: left;
      .allprices {
        display: inline-block;
        width: 1.5rem;
        height: 0.3rem;
        margin-top: 0.1rem;
        box-sizing: border-box;
      }
    }
    .xd {
      width: 2rem;
      height: 100%;
      background: red;
      padding-right: 0.3rem;
      line-height: 1rem;
      box-sizing: border-box;
    }
  }
}
.shopings {
  padding-top: 0.57rem;
  width: 5.2rem;
  overflow: hidden;
}
.lickss {
  width: 100%;
  height: 70%;
  border-bottom: 2rem;
  .lick-p {
    width: 100%;
    height: 1rem;
    text-align: center;
    align-items: center;
    line-height: 1rem;
    font-size: 0.35rem;
  }
  ul {
    width: 100%;
    height: 100%;
    overflow: auto;
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;
    margin-bottom: 2rem;
    padding: 0 0.2rem;
    justify-content: space-between;
    font-size: 0.23rem;
    li {
      width: 3.35rem;
      position: relative;
      img {
        width: 100%;
        height: 4rem;
        display: block;
      }
      .p1 {
        width: 100%;
        height: 0.45rem;
        background: #f0edd4;
        color: #b69b72;
        position: absolute;
        left: 0;
        top: 3.55rem;
        line-height: 0.45rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .p2 {
        font-size: 0.2rem;
        margin-top: 0.13rem;
        color: #666;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .p3 {
        display: flex;
        -webkit-box-pack: justify;
        justify-content: space-between;
        -webkit-box-align: center;
        align-items: center;
        font-size: 0.2rem;
        margin-top: 0.13rem;
      }
    }
  }
}
</style>
